/**
 * http配置
 */
import axios from 'axios'

// 环境的切换
if (process.env.NODE_ENV == 'development') {
    axios.defaults.baseURL = '/fireApi';
} else if (process.env.NODE_ENV == 'debug') {
    axios.defaults.baseURL = '/fireApi';
} else if (process.env.NODE_ENV == 'production') {
    // axios.defaults.baseURL = 'http://61.142.244.16:19835/';
    axios.defaults.baseURL = 'http://192.168.20.175:19835/';
    // axios.defaults.baseURL = 'http://47.95.117.185:9836/';
}

// post请求头
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';

// http request 拦截器
axios.interceptors.request.use(
    config => {
        config.timeout = 1000000;
        return config;
    },
    err => {
        return Promise.reject(err);
    });

// http response 拦截器
axios.interceptors.response.use(
    response => {
        switch (response.data.status) {
            case '200':
                return response.data;
            case '401':
                //Token问题
                alert('登入失效,请重新登入');
                return;
            default:
                return response.data;
        }
    },
    error => {
        return Promise.reject(error.response.data)
    });

export default axios;
